
package gal.game.core.resource
{
	import com.greensock.TweenNano;
	
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	
	
	/**
	 * @author 缺硒
	 */
	public class GameLoader extends Loader
	{
		private var _url:String;
		
		// 构造函数
		public function GameLoader(url:String = "")
		{
			if(url != "") loadElement(url);
		}
		
		public function loadElement(url:String):void
		{
			_url = url;
			alpha = 0;
			unload();
			
			contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
			contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
			load(new URLRequest(url));
		}
		
		public function onComplete(evt:Event):void
		{
			contentLoaderInfo.removeEventListener(Event.COMPLETE, onComplete);
			contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onError);
			trace("ok")
			TweenNano.to(this, 0.3, {alpha:1});
		}
		
		public function onError(evt:IOErrorEvent):void
		{
			trace("加载失败: ", evt);
		}
		//
	}
}